<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
    <style type="text/css">
        .layui-table-cell{
            height: auto;
            line-height: 50px;
        }
    </style>
</head>
<body>
<div class="layui-panel" style="padding: 8px;">
    <fieldset class="layui-elem-field  layui-border-blue">
        <legend>搜索区域</legend>
        <form class="layui-form layui-form-pane" style="margin: 20px;">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="user" autocomplete="off" placeholder="请输入用户名" />
                    </div>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="id" autocomplete="off" placeholder="请输入反馈id" />
                    </div>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchBtn">
                        <i class="layui-icon layui-icon-search"></i>
                        查找
                    </a>
                    <a class="layui-btn layui-btn-normal" lay-submit="" lay-filter="">
                        <i class="layui-icon layui-icon-down"></i>
                        导出
                    </a>
                </div>
            </div>
        </form>
    </fieldset>
    <div class="layui-table-cell">
        <table id="feedbackTable" lay-filter="feedbackTable" class="layui-table layui-form" ></table>
    </div>
    <script id="tableBar" type="text/html">
        <a class="layui-btn layui-btn-normal layui-btn-md" lay-event="add">
            <i class="layui-icon layui-icon-add-1"></i>
            新增
        </a>
        <!--<a class="layui-btn layui-btn-danger layui-btn-md" lay-event="delete">
            <i class="layui-icon layui-icon-delete"></i>
            删除
        </a>-->
    </script>

    <script id="tool" type="text/html">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">详情</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
    </script>
    <script id="photo" type="text/html">
        <img src="/file/fc/showImg/{{d.feedbackPhoto}}" style="width: 100px;height: 60px;">
    </script>
</div>
<script>
    var $;


    layui.use(['table','form','jquery'],function(){
        var table = layui.table,form = layui.form;$=layui.jquery;


        //加载表格
        table.render({
            elem:'#feedbackTable',
            height:'full-160',
            toolbar:'#tableBar',
            url:"/feedback/fc/find",
            page: {
                theme:'#1e9fff'
            },
            cols:[
                [
                    {field:'id',title:'反馈id',width:100,align:'center'},
                    {field:'user',title:'用户名',width:150,align:'center'},
                    {field:'phone',title:'手机号码',width:200,align:'center'},
                    {field:'content',title:'反馈内容',width:300,align:'center'},
                    {field:'feedbackPhoto',title:'反馈图片',width:180,templet: '#photo',align:'center'},
                    {field:'type',title:'反馈类型',width:200,align:'center',
                        templet:function (res) {
                            if("1" == res.type){return "<span style='background-color: #e8f4ff;border-color:#d1e9ff;color: #1890ff;border-radius:5px;padding: 0px 10px;display:inline-block'>七天无理由</span>"}
                            else if("2" == res.type){return "<span style='background-color: #e8f4ff;border-color:#d1e9ff;color: #1890ff;border-radius:5px;padding: 0px 10px;display:inline-block'>卖家发错货</span>"}
                            else if("3" == res.type){return "<span style='background-color: #e8f4ff;border-color:#d1e9ff;color: #1890ff;border-radius:5px;padding: 0px 10px;display:inline-block'>尺码不合适</span>"};
                        }},
                    {field:'createTime',title:'反馈时间',width:200,align:'center'},
                    {fixed:'right',title:'操作',align:'center',toolbar:'#tool'}
                ]
            ],

        })
        //监听搜索按钮
        form.on('submit(searchBtn)',function(data){
            var dataForm = data.field;

            table.reload('feedbackTable',{
                where:{
                    user:dataForm.user,
                    id:dataForm.id
                }

            })
        })

        var active = {
            addOrUpdate:function (content){
                var b = false;
                top.layer.open({
                    type:2,
                    content:content,
                    area:['700px','800px'],
                    btn:['确定保存','取消关闭'],
                    btn1:function (i,o){
                        b = true;
                        o.find('iframe')[0].contentWindow.btnSubmit();
                    },
                    end:function (){
                        if (b) layui.table.reload('feedbackTable');
                    }
                })
            },
            deleteConfirm:function (id) {
                $.ajax({
                    type:'post',
                    url:'/feedback/fc/delete',
                    dataType: 'json',
                    data:{
                        id:id,
                    },
                    success:function (result) {
                        var tip = result.msg;
                        layer.msg(tip);
                        if(result.is){
                            layui.table.reload('feedbackTable');
                        }
                    }
                })
            }
        }

        table.on('tool(feedbackTable)',function (obj){
            var event = obj.event;
            if("edit" == event){
                active.addOrUpdate('/page/feedback/feedbackEdit/'+obj.data.id);
            }else if ("delete == event"){
                active.deleteConfirm(obj.data.id);
            }
        })
        table.on('toolbar(feedbackTable)',function (obj) {
            var event = obj.event;
            if("add" == event){
                active.addOrUpdate('/page/feedback/feedbackAdd');
            }
        })
    });

</script>
</body>
</html>